package com.ror.java.se.exception;

public class Demo01 {
    public static void main(String[] args) {
        int[] arr = {1, 4, 7, 3, 2, 9, 8};
        System.out.println(maxOf(arr));
    }

    //方法的运行时异常可以不声明，因为编译器管不到运行时异常，声明了也好，提高可读性
    static int maxOf(int[] arr) /*throws NullPointerException, ArrayIndexOutOfBoundsException*/ {
        //数组未创建
        if (arr == null) throw new NullPointerException();
        //空数组
        if (arr.length == 0) throw new ArrayIndexOutOfBoundsException();

        int max = arr[0];
        for (int i : arr) max = Math.max(i, max);
        return max;
    }
}
